<?php
namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Kra8\Snowflake\HasSnowflakePrimary;
use Illuminate\Database\Eloquent\SoftDeletes;

class DeviceOrder extends Model
{
    use SoftDeletes;
    use HasSnowflakePrimary;

    protected $fillable = [
        'user_id',
        'quantity',
        'device_group_id',
        'factory_user_id',
        'transfer_voucher',
        'ship_voucher',
        'refund_voucher',
        'receipt_voucher',
        'cost_total_price',
        'cost_unit_price',
        'before_profit',
        'after_profit',
        'original_price',
        'discount_price',
        'total_sales_amount',
        'factory_time',
        'payment_time',
        'receipt_time',
        'style',
        'receiver',
        'receiving_call',
        'shipping_address',
        'shipping_address_detail',
        'sender',
        'shipping_call',
        'delivery_address',
        'delivery_address_detail',
        'create_remark',
        'pay_remark',
        'ship_remark',
        'receipt_remark',
        'install_remark',
        'refund_remark',
        'status',
        'pay_user_id',
        'delivery_user_id',
        'receipt_user_id'
    ];
    public function author()
    {
        return $this->belongsTo('App\Models\User', 'user_id');
    }
    public function factory()
    {
        return $this->belongsTo('App\Models\User', 'factory_user_id');
    }
    public function pay_user()
    {
        return $this->belongsTo('App\Models\User', 'pay_user_id');
    }
    public function receipt_user()
    {
        return $this->belongsTo('App\Models\User', 'receipt_user_id');
    }
    public function delivery_user()
    {
        return $this->belongsTo('App\Models\User', 'delivery_user_id');
    }
    public function device_group()
    {
        return $this->belongsTo('App\Models\Group', 'device_group_id');
    }
    public function factory_devices(){
        return $this->hasMany('App\Models\FactoryDevice', 'device_order_id');
    }
    public function devices(){
        return $this->hasMany('App\Models\Device', 'device_order_id');
    }
}
